{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Activation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from chemprop.nn.utils import Activation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Activation functions\n",
    "\n",
    "The following activation functions can be specified by name (e.g., `activation = \"relu\"`):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "relu\n",
      "leakyrelu\n",
      "prelu\n",
      "tanh\n",
      "elu\n"
     ]
    }
   ],
   "source": [
    "for activation in Activation:\n",
    "    print(activation)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AtomMessagePassing(\n",
       "  (W_i): Linear(in_features=72, out_features=300, bias=False)\n",
       "  (W_h): Linear(in_features=314, out_features=300, bias=False)\n",
       "  (W_o): Linear(in_features=372, out_features=300, bias=True)\n",
       "  (dropout): Dropout(p=0.0, inplace=False)\n",
       "  (tau): ReLU()\n",
       "  (V_d_transform): Identity()\n",
       "  (graph_transform): Identity()\n",
       ")"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from chemprop.nn import AtomMessagePassing\n",
    "\n",
    "mp = AtomMessagePassing(activation=\"relu\")\n",
    "\n",
    "mp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Custom"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Custom activation functions can be used by passing a PyTorch module to the `MessagePassing` or `Predictor` constructor.\n",
    "\n",
    "See [Non-linear Activations (weighted sum, nonlinearity)](https://docs.pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearity) and [Non-linear Activations (other)](https://docs.pytorch.org/docs/stable/nn.html#non-linear-activations-other) for common PyTorch activation functions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AtomMessagePassing(\n",
       "  (W_i): Linear(in_features=72, out_features=300, bias=False)\n",
       "  (W_h): Linear(in_features=314, out_features=300, bias=False)\n",
       "  (W_o): Linear(in_features=372, out_features=300, bias=True)\n",
       "  (dropout): Dropout(p=0.0, inplace=False)\n",
       "  (tau): Softplus(beta=1.0, threshold=20.0)\n",
       "  (V_d_transform): Identity()\n",
       "  (graph_transform): Identity()\n",
       ")"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "mp = AtomMessagePassing(activation=torch.nn.Softplus())\n",
    "\n",
    "mp"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "chemprop",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
